package com.atguigu.create.factory.simplefactory.order;

import com.atguigu.create.factory.simplefactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {
    private PizzaSimpleFactory pizzaSimpleFactory;

    public void setPizzaSimpleFactory(PizzaSimpleFactory pizzaSimpleFactory) {
        this.pizzaSimpleFactory = pizzaSimpleFactory;
    }


    public void startOrder(){
        do{
            String type = getType();
            Pizza pizza = pizzaSimpleFactory.createPizza(type);
            if(pizza==null){
                System.out.println("not found this type pizza");
            }else{
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        }while (true);


    }


    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
